import React, { Component } from 'react'
import { Button, TextInput, View } from 'react-native'

export default class UserEditor extends Component {
    state={user:{}}
    componentDidMount(){
        this.setState({user:this.props.user})
    }
    _unameChange=txt=>{
        let user=this.state.user
        user.uname=txt
        this.setState({user})
    }
    _addressChange=txt=>{
        let user=this.state.user
        user.address=txt
        this.setState({user})
    }
    _update=()=>{
        this.props.onUserUpdate(this.state.user)
    }
    render() {
        return (
            <View>
                <TextInput value={this.state.user.uname} onChangeText={this._unameChange}/>
                <TextInput value={this.state.user.address} onChangeText={this._addressChange}/>
                <Button title="更新" onPress={this._update}/>
            </View>
        )
    }
}
